using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ItemMatchingCodeMap : EntityTypeConfiguration<ItemMatchingCode>
    {
        public ItemMatchingCodeMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Guarantor)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.Item)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.Code)
                .HasMaxLength(20);

            this.Property(t => t.Description)
                .HasMaxLength(250);

            // Table & Column Mappings
            this.ToTable("ItemMatchingCode");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Guarantor).HasColumnName("Guarantor");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Description).HasColumnName("Description");

            // Relationships
            this.HasRequired(t => t.Cust)
                .WithMany(t => t.ItemMatchingCodes)
                .HasForeignKey(d => d.Guarantor);
            this.HasRequired(t => t.Item1)
                .WithMany(t => t.ItemMatchingCodes)
                .HasForeignKey(d => d.Item);

        }
    }
}
